﻿@using WebSite.ViewModels.Fields;

@model WebSite.ViewModels.FormLayoutViewModel

@{ IEnumerable<IField> allFields = Model.Fields.Where(x => !x.IsEmpty); }

<table cellspacing="@Model.CellSpacing">
@{ IEnumerable<IField> fields = allFields.Where(x => !x.IsOneRow); }

@for (int i = 0; i < fields.Count(); i += Model.Columns)
{
    <tr class="field">
        @for (int j = 0; j < Model.Columns; j++)
        {
            if (i + j < fields.Count())
            {
                IField field = fields.ElementAt(i + j);
                <td align="right" style="font-weight:bold;@(j == 0 ? String.Empty : "padding-left:30px")">@field.Caption:</td>
                <td style="padding-left:5px">@field.Render(Html)</td>
            }
            else
            {
                <td colspan="@((Model.Columns - j) * 2)" />
                break;
            }
        }
    </tr>
}

@{ fields = allFields.Where(x => x.IsOneRow); }
@foreach (IField field in fields)
{
    <tr class="field">
        <td align="right" style="font-weight:bold">@field.Caption:</td>
        <td style="padding-left:5px" colspan="@((Model.Columns * 2) - 1)">@field.Render(Html)</td>
    </tr>
}

</table>
